#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>

int main(int argc, char *argv[])
{
    char **pp;
    struct in_addr addr;
    struct hostent *hostp;

    if (argc != 2)
    {
        printf("usage: %s <domain name or dotted-decimal>\n", argv[0]);
        exit(1);
    }

    if (inet_aton(argv[1], &addr) != 0)
        hostp = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET);
    else
        hostp = gethostbyname(argv[1]);

    if (hostp == NULL)
    {
        printf("usage: %s <domain name or dotted-decimal>\n", argv[0]);
        exit(1);
    }

    printf("official hostname: %s\n", hostp->h_name);

    for (pp = hostp->h_aliases; *pp != NULL; pp++)
        printf("alias: %s\n", *pp);

    for (pp = hostp->h_addr_list; *pp != NULL; pp++)
        printf("address: %s\n", (char *)(inet_ntoa(*(struct in_addr *)*pp)));

    return 0;
}
